package week6;


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Ex59 {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new FileReader("src/week6/p059_cipher.txt"));
        String[] strs = reader.readLine().split(",");
        List<Integer> ciphertext1 = new ArrayList<>();
        List<Integer> ciphertext2 = new ArrayList<>();
        List<Integer> ciphertext3 = new ArrayList<>();
        Integer temp;
        for (int i = 0; i < strs.length; ++i){
            temp = Integer.valueOf(strs[i]);
            if (i % 3 == 0)
                ciphertext1.add(temp);
            else if (i % 3 == 1)
                ciphertext2.add(temp);
            else ciphertext3.add(temp);
        }
        int key1 = most(ciphertext1) ^ 32;
        int key2 = most(ciphertext2) ^ 32;
        int key3 = most(ciphertext3) ^ 32;
        int ans = 0;
        ans += ciphertext1.stream().mapToInt(x -> x ^ key1).sum();
        ans += ciphertext2.stream().mapToInt(x -> x ^ key2).sum();
        ans += ciphertext3.stream().mapToInt(x -> x ^ key3).sum();
        System.out.println(ans);
    }
    public static int most(List<Integer> list){
        Collections.sort(list);
        int temp = list.get(0), count = 0;
        int most = temp, max = 0;
        for (int x : list){
            if (temp != x){
                if (count > max){
                    max = count;
                    most = temp;
                }
                count = 0;
                temp = x;
            }
            count++;
        }
        if (count > max)    most = temp;
        return most;
    }
}
